import SwiftUI
// 自定义上半部分为圆角的矩形形状
struct RoundedTopRectangle: Shape {
    var cornerRadius: CGFloat

    func path(in rect: CGRect) -> Path {
            var path = Path()
            let radius = min(cornerRadius, rect.height / 2)

            // 从左上角开始绘制路径
            path.move(to: CGPoint(x: rect.minX + radius, y: rect.minY))

            // 绘制顶部左边的圆角
            path.addArc(center: CGPoint(x: rect.minX + radius, y: rect.minY + radius),
                        radius: radius,
                        startAngle: .degrees(180),
                        endAngle: .degrees(270),
                        clockwise: false)

            // 绘制顶部
            path.addLine(to: CGPoint(x: rect.maxX - radius, y: rect.minY))

            // 绘制顶部右边的圆角
            path.addArc(center: CGPoint(x: rect.maxX - radius, y: rect.minY + radius),
                        radius: radius,
                        startAngle: .degrees(270),
                        endAngle: .degrees(0),
                        clockwise: false)

            // 绘制右边
            path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))

            // 绘制底部
            path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))

            // 绘制左边
            path.addLine(to: CGPoint(x: rect.minX, y: rect.minY + radius))
        
        

            path.closeSubpath()

            return path
        }
    
}
